
package boundary;

import entity.Reservasi;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "ReservasiServlet", urlPatterns = {"/ReservasiServlet"})
public class ReservasiServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String page = request.getParameter("page");
        RequestDispatcher res = null;

        String errornama = "";
        String nama = request.getParameter("nama");

        if (nama != null) {
            if (nama.equals("")) {
                nama = "nama tidak boleh kosong !!";
            }
        }
        if (!"".equals(nama)) {
            request.setAttribute("nama", nama);
        }
        String errortelepon = "";
        String telepon = request.getParameter("telepon");

        if (telepon != null) {
            if (telepon.equals("")) {
                telepon = "telepon tidak boleh kosong !!";
            }
        }
        if (!"".equals(telepon)) {
            request.setAttribute("telepon", telepon);
        }
        String erroremail = "";
        String email = request.getParameter("email");

        if (email != null) {
            if (email.equals("email")) {
                email = "email tidak boleh kosong !!";
            }
        }
        if (!"".equals(email)) {
            request.setAttribute("email", email);
        }
        String errorreservasi = "";
        String reservasi = request.getParameter("reservasi");

        if (reservasi != null) {
            if (reservasi.equals("")) {
                reservasi = "reservasi tidak boleh kosong !!";
            }
        }
        if (!"".equals(reservasi)) {
            request.setAttribute("reservasi", reservasi);
        }
        String errortanggal = "";
        String tanggal = request.getParameter("tanggal");

        if (tanggal != null) {
            if (tanggal.equals("")) {
                tanggal = "tanggal tidak boleh kosong !!";
            }
        }
        if (!"".equals(tanggal)) {
            request.setAttribute("tanggal", tanggal);
        }
        String erroracara = "";
        String acara = request.getParameter("acara");

        if (acara != null) {
            if (acara.equals("")) {
                acara = "field acara tidak boleh kosong !!";
            }
        }
        if (!"".equals(acara)) {
            request.setAttribute("acara", acara);
        }
        String erroreprmintaan = "";
        String permintaan = request.getParameter("permintaan");

        if (permintaan != null) {
            if (permintaan.equals("")) {
                permintaan = "field permintaan tidak boleh kosong !!";
            }
        }
        if (!"".equals(permintaan)) {
            request.setAttribute("permintaan", permintaan);
        }
        String errorjumlah = "";
        String jumlah = request.getParameter("jumlah");

        if (jumlah != null) {
            if (jumlah.equals("")) {
                jumlah = "field jumlah tidak boleh kosong !!";
            }
        }
        if (!"".equals(jumlah)) {
            request.setAttribute("jumlah", jumlah);
        }

        Reservasi Reservasi = new Reservasi();
        Reservasi dm = new Reservasi();
        if (request.getParameter("nama") != null) {
            Reservasi.setNama(nama);
            Reservasi.setTelepon(telepon);
            Reservasi.setEmail(email);
            Reservasi.setreservasi(reservasi);
            Reservasi.setTanggal(tanggal);
            Reservasi.setAcara(acara);
            Reservasi.setPermintaan(permintaan);
            Reservasi.setJumlah(jumlah);


            //   dm.create(Reservasi);
            response.sendRedirect(response.encodeRedirectURL(""));
        } else {
            //request.setAttribute("errorNama", errorNama);
            request.getRequestDispatcher("halaman_menu.jsp").include(request, response);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
